﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class myproblemedit : AdminpageBase
{ 
    protected string ctype = ReadRequest.RequestString("t"); 
    protected long id = ReadRequest.RequestLong("id");
    protected Model.LotteryDes model = new Model.LotteryDes();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
        if (ctype == "edit")
        {
            Model.LotteryDes model = BLL.LotteryDes.GetModel(id);
             textQS.Text=model.Name;
             txtNo.Value =model.answer;  
        }
    }

    //提交按钮事件
    protected void btn_submit_Click(object sender, EventArgs e)
    {
        save_Newscont();
    }
    private void save_Newscont()
    {
        //获取登录信息
        Model.Manageadmin loginUserInfo_cur = BLL.CMember.ManageadminLoginInfo();
        //没有登录
        if (loginUserInfo_cur == null)
        {
            alertmessageAndGoback("保存失败");
            return;
        }
        if (ctype == "edit") {
            Model.LotteryDes model = BLL.LotteryDes.GetModel(id); 
            model.Name = textQS.Text;
            model.answer = txtNo.Value;
            model.Addtime = DateTime.Now;
            if (BLL.LotteryDes.Update(model) > 0)
            {
                alertmessageAndGo("更新成功！", "/manage/myproblem.aspx");
                return;
            }
            else
            {
                alertmessageAndGoback("更新失败");
                return;
            }
        }
        else
        {
            if (textQS.Text == "")
            {
                alertmessageAndGoback("请输入问题");
                return;
            }
            if (txtNo.Value == "")
            {
                alertmessageAndGoback("请输入答案");
                return;
            }

            Model.LotteryDes model = new Model.LotteryDes();
            model.type = int.Parse(caipiaoType.SelectedValue);
            model.Name = textQS.Text;
            model.answer = txtNo.Value;
            model.Addtime = DateTime.Now;
            if (BLL.LotteryDes.Add(model) > 0)
            {
                alertmessageAndGo("保存成功！", "/manage/myproblem.aspx");
                return;
            }
            else
            {
                alertmessageAndGoback("保存失败");
                return;
            }
        }
    }
}